package com.irdstudio.apicenter.console.controller.itom;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.irdstudio.apicenter.console.controller.MacmsBaseAction;
import com.irdstudio.apicenter.frame.core.jdbc.container.PageInfo;
/**
 * 应用运维管理主类
 * @author guangming.li
 * @version 1.0
 * @date 2016-02-19
 */
@Controller
@RequestMapping(value = "/itom")
public class ItomMainAction extends MacmsBaseAction{

	@RequestMapping(value = "itomIndex")
	public ModelAndView itomIndex(HttpServletRequest request) throws Exception {
		String appid = request.getParameter("appid");
		String appName = java.net.URLDecoder.decode(request
				.getParameter("appName"), "UTF-8");
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("appid", appid);
		modelAndView.addObject("appName", appName);
		modelAndView.setViewName("itom/itomIndex");
		return modelAndView;
	}
	
	/**
	 * J2EE应用运维管理
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "j2eeItomIndex")
	public ModelAndView j2eeItomIndex(HttpServletRequest request) throws Exception {
		String appid = request.getParameter("appid");
		String appName = java.net.URLDecoder.decode(request
				.getParameter("appName"), "UTF-8");
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("appid", appid);
		modelAndView.addObject("appName", appName);
		modelAndView.setViewName("itom/j2eeItomIndex");
		return modelAndView;
	}	
	
	/**
	 * 应用服务器列表
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "appServerList")
	public ModelAndView appServerList(HttpServletRequest request) throws Exception {
		
		// 取得传入应用标识
		String appId = request.getParameter("appid");
		if (StringUtils.isEmpty(appId)) {
			throw new Exception("必须传入应用标识(appid)参数!");
		}

		// 查询应用服务器列表并放入到上下文中
		String sql = "select * from app_server where app_id=?";
		PageInfo abiPageInfo = new PageInfo();
		context.addDataList("asList", this.getTableModelDAO().queryList(sql,
				abiPageInfo, new Object[] { appId }));
		context.addPageInfo("asList", abiPageInfo);

		// 将数据上下文放到属性中
		request.setAttribute("context", super.context);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("itom/appServerList");
		return modelAndView;
	}
}
